<template>
  <!-- Webview Web View -->
  <web-view :src="url" :update-title="true" @load="load" @error="error" />
</template>

<script lang="ts" setup>
  import { onLoad } from '@/router';
  import { ref } from 'vue';
  import { onUnload } from '@dcloudio/uni-app';
  import { type Webview } from '@/router/types/modules';

  /**  Webview  Web View */
  const url = ref('');
  let unLoadCallback: Webview['unLoadCallback'];
  onLoad<'Webview'>((op) => {
    op.title &&
      uni.setNavigationBarTitle({
        title: op.title,
      });
    url.value = op.url;
    unLoadCallback = op.unLoadCallback;
  });

  function load(e: any) {
    console.log('webview onLoad', e);
  }

  function error(e: any) {
    console.log('webview onError', e);
  }

  onUnload(() => unLoadCallback?.());
</script>
